package com.qyhl.cloud.webtv.module_integral.wallet;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.qyhl.webtv.commonlib.entity.intergral.WallerBean;
import com.qyhl.cloud.webtv.module_integral.wallet.goldcoin.GlodFragment;
import com.qyhl.cloud.webtv.module_integral.wallet.money.FforwardHistoryFragment;
import com.qyhl.cloud.webtv.module_integral.wallet.money.MoneyFragment;

import java.util.ArrayList;

public class WalletPresenter implements WallerContract.WallerPresenter {
    private WallerContract.WallerView view;
    private WallerContract.WallerModel model;

    public WalletPresenter(WallerContract.WallerView view) {
        this.view = view;
        model = new WalletModel(this);
    }

    @Override
    public MAdapter getTabAdapter(FragmentActivity activity) {
        return new MAdapter(activity.getSupportFragmentManager());
    }

    @Override
    public void getData() {
        model.getData();
    }

    @Override
    public void getDataError(String message) {
        view.getDataError(message);
    }

    @Override
    public void getDataSuccess(WallerBean data) {
        view.getDataSuccess(data);
    }

    @Override
    public void onDestroy() {
        view = null;
        model.onDestroy();
    }

    @Override
    public void getCoinRate() {
        model.getCoinRate();
    }

    @Override
    public void getCoinRateSuccess(int rate) {
        view.getCoinRateSuccess(rate);
    }

    class MAdapter extends FragmentPagerAdapter {
        ArrayList<Fragment> fragments = new ArrayList<>();
        String[] names = new String[]{"金币", "零钱", "提现记录"};

        public MAdapter(FragmentManager fm) {
            super(fm);
            fragments.add(new GlodFragment());
            fragments.add(new MoneyFragment());
            fragments.add(new FforwardHistoryFragment());
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return names[position];
        }
    }
}
